package com.zzz.codegen.register;

import cn.hutool.db.meta.JdbcType;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import static cn.hutool.db.meta.JdbcType.*;

public class PropertyTypeRegister {
    private static Map<JdbcType, Class> propertyTypeMap = new LinkedHashMap<>();

    static {
        //Number
        propertyTypeMap.put(INTEGER, Integer.class);
        propertyTypeMap.put(SMALLINT, Short.class);
        propertyTypeMap.put(BIGINT, Long.class);
        //BigDecimal
        propertyTypeMap.put(REAL, BigDecimal.class);
        propertyTypeMap.put(FLOAT, BigDecimal.class);
        propertyTypeMap.put(DOUBLE, BigDecimal.class);
        propertyTypeMap.put(NUMERIC, BigDecimal.class);
        propertyTypeMap.put(DECIMAL, BigDecimal.class);
        //String
        propertyTypeMap.put(CHAR, String.class);
        propertyTypeMap.put(VARCHAR, String.class);
        propertyTypeMap.put(LONGVARCHAR, String.class);
        propertyTypeMap.put(NVARCHAR, String.class);
        propertyTypeMap.put(NCHAR, String.class);
        propertyTypeMap.put(NCLOB, String.class);
        propertyTypeMap.put(TINYINT, String.class);
        propertyTypeMap.put(BINARY, String.class);
        propertyTypeMap.put(VARBINARY, String.class);
        propertyTypeMap.put(LONGVARBINARY, String.class);
        propertyTypeMap.put(CLOB, String.class);
        propertyTypeMap.put(BLOB, String.class);
        //时间
        propertyTypeMap.put(DATE, LocalDateTime.class);
        propertyTypeMap.put(TIME, LocalDateTime.class);
        propertyTypeMap.put(TIMESTAMP, LocalDateTime.class);
        //布尔
        propertyTypeMap.put(BOOLEAN, Boolean.class);
        propertyTypeMap.put(BIT, boolean.class);
    }

    public static void register(JdbcType jdbcType, Class propertyTypeClz) {
        propertyTypeMap.put(jdbcType, propertyTypeClz);
    }

    public static Class getPropertyTypeClz(JdbcType jdbcType) {
        Class propertyTypeClz = propertyTypeMap.get(jdbcType);
        return propertyTypeClz == null ? Object.class : propertyTypeClz;
    }
}
